package com.foreknow.demo15;

import java.util.*;

public class Example {
    public static void main(String[] args) {
        //创建List集合
        List<Map<String,Student>> list = new ArrayList<>();
        //创建3个Map
        Map<String,Student> map1 = new HashMap<>();
        Student s1 = new Student();
        s1.setName("xx1");
        Student s2 = new Student();
        s2.setName("xx2");
        map1.put("s1",s1);
        map1.put("s2",s2);
        Map<String,Student> map2 = new HashMap<>();
        Student s3 = new Student();
        s3.setName("xx3");
        Student s4 = new Student();
        s4.setName("xx4");
        map2.put("s3",s3);
        map2.put("s4",s4);
        Map<String,Student> map3 = new HashMap<>();
        Student s5 = new Student();
        s5.setName("xx5");
        Student s6 = new Student();
        s6.setName("xx6");
        map3.put("s5",s5);
        map3.put("s6",s6);
        //将Map添加到List集合中
        list.add(map1);
        list.add(map2);
        list.add(map3);
        //遍历输出学生信息
//        for(int i = 0;i<list.size();i++) {
//            Map<String,Student> m = list.get(i);
//            Set<Map.Entry<String,Student>> s = m.entrySet();
//            Iterator<Map.Entry<String,Student>> it = s.iterator();
//            while (it.hasNext()) {
//                Map.Entry<String,Student> entry = it.next();
//                System.out.println(entry.getKey() + "---" + entry.getValue().getName());
//            }
//        }
        System.out.println("-----------------------------------------------------------------");

//        for (Map<String,Student> map:list) {
//            Set<Map.Entry<String,Student>> s = map.entrySet();
//            Iterator<Map.Entry<String,Student>> it = s.iterator();
//            while (it.hasNext()) {
//                Map.Entry<String,Student> entry = it.next();
//                System.out.println(entry.getKey() + "---" + entry.getValue().getName());
//            }
//        }

        Iterator<Map<String,Student>> it = list.iterator();
        while (it.hasNext()) {
            Map<String,Student> m = it.next();
            Set<Map.Entry<String,Student>> s = m.entrySet();
            Iterator<Map.Entry<String,Student>> its = s.iterator();
            while (its.hasNext()) {
                Map.Entry<String,Student> entry = its.next();
                System.out.println(entry.getKey() + "---" + entry.getValue().getName());
            }
        }
    }
}
